//
// Created by hoyin on 2022/2/23.
//

#ifndef AUST_RM_VISION_2022_CHRONO_H
#define AUST_RM_VISION_2022_CHRONO_H

#include <chrono>

class Chrono {
private:
	std::chrono::steady_clock::time_point timeStart;
	std::chrono::steady_clock::time_point prevTimePoint;
	std::chrono::steady_clock::time_point curTimePoint;
public:
	Chrono() {
		reset();
	}

//	返回上一次timeSpan到此次timeSpan的时间间隔
	double timeSpan() {
		curTimePoint = std::chrono::steady_clock::now();
		std::chrono::duration<double> timeCost = std::chrono::duration_cast<std::chrono::duration<double>>(curTimePoint - prevTimePoint);
		prevTimePoint = std::chrono::steady_clock::now();
		return timeCost.count();
	}

//	返回从reset到timeCost的总时间间隔
	double timeCost() {
		curTimePoint = std::chrono::steady_clock::now();
		prevTimePoint = std::chrono::steady_clock::time_point(curTimePoint);
		std::chrono::duration<double> timeCost = std::chrono::duration_cast<std::chrono::duration<double>>(curTimePoint - timeStart);
		return timeCost.count();
	}

	void reset() {
		timeStart = std::chrono::steady_clock::now();
		prevTimePoint = std::chrono::steady_clock::time_point(timeStart);
	}
};


#endif //AUST_RM_VISION_2022_CHRONO_H
